/*--------------------环境模块.设备管理--ly-----------------*/
/*--------------------设备规则新增功能 en_warningrule_add.html------------------*/

layui.use(['form', 'layer'], function() {
	$ = layui.jquery;
	var form = layui.form,
		layer = layui.layer;

	//自定义验证规则
	form.verify({
		rulename: function(value) {
			if(value.length < 6) {
				return '昵称至少得6个字符啊！';
			}
		}
	});

	var url = environmentport + "/RuleController/addEnergy"; //请求数据url

	//post请求
	var postResult = (function() {
		$.get(url, $('#ruleadd').serialize(),
			function(result) {
				if(result.code == '0') {
					layer.alert("增加成功", {
						icon: 6
					}, function() {
						// 获得frame索引
						var index = parent.layer.getFrameIndex(window.name);
						//关闭当前frame
						parent.layer.close(index);
					});
				} else {
					layer.alert("服务器繁忙，稍后再试", {
						icon: 5
					}, function() {
						// 获得frame索引
						var index = parent.layer.getFrameIndex(window.name);
						//关闭当前frame
						parent.layer.close(index);
					});
				}
			})
	});

	//监听提交
	form.on('submit(add)', function(data) {
		console.log(data);
		//发异步，把数据提交给php
		postResult(data);
		return false;
	});
});